package com.chzc.po;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 商品表
 * @author CV大魔王
 * @since 2021-05-27
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("mq_goods")
@ApiModel(value = "Goods对象", description = "商品表")
public class Goods implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "商品ID")
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    private String id;

    @ApiModelProperty(value = "商品标题")
    private String goodsTitle;

    @ApiModelProperty(value = "商品图片")
    private String goodsImg;

    @ApiModelProperty(value = "商品简介")
    private String goodsContent;

    @ApiModelProperty(value = "商品详情介绍")
    private String goodsDetail;

    @ApiModelProperty(value = "商品详情md格式")
    private String goodsDetailMd;

    @ApiModelProperty(value = "商品单价")
    private BigDecimal goodsPrice;

    @ApiModelProperty(value = "秒杀价")
    private BigDecimal seckillPrice;

    @ApiModelProperty(value = "商品库存")
    private Integer goodsStock;

    @ApiModelProperty(value = "秒杀开始时间")
    private Date startDate;

    @ApiModelProperty(value = "秒杀结束时间")
    private Date endDate;

    @ApiModelProperty(value = "创建时间")
    private Date createTime;

    @ApiModelProperty(value = "更新时间")
    private Date updateTime;

    @ApiModelProperty(value = "状态：0删除 1正常")
    private Integer status;


    @ApiModelProperty(value = "1可以购买 0无法购买")
    @TableField(exist = false)
    private Integer itemKill;

    public Integer getItemKill() {
        // 库存不足
        if (this.goodsStock <=0) {
            return 0;
        }
        // 未开始
        if (this.startDate.getTime() > System.currentTimeMillis()) {
            return 0;
        }
        // 已结束
        if (this.endDate.getTime() < System.currentTimeMillis()) {
            return 0;
        }
        return 1;
    }

}
